/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.apestar.modules.report.withdrawcashremind.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.apestar.common.config.Global;
import cn.apestar.common.persistence.Page;
import cn.apestar.common.utils.StringUtils;
import cn.apestar.common.web.BaseController;
import cn.apestar.modules.report.withdrawcashremind.entity.WithdrawCashRemind;
import cn.apestar.modules.report.withdrawcashremind.service.WithdrawCashRemindService;

/**
 * 提现提醒Controller
 * @author yudw
 * @version 2016-08-20
 */
@Controller
@RequestMapping(value = "${adminPath}/withdrawcashremind/withdrawCashRemind")
public class WithdrawCashRemindController extends BaseController {

    @Autowired
    private WithdrawCashRemindService withdrawCashRemindService;

    @ModelAttribute
    public WithdrawCashRemind get(@RequestParam(required = false) String id) {
        WithdrawCashRemind entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = withdrawCashRemindService.get(id);
        }
        if (entity == null) {
            entity = new WithdrawCashRemind();
        }
        return entity;
    }

    @RequestMapping(value = {"list" , ""})
    public String list(WithdrawCashRemind withdrawCashRemind, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<WithdrawCashRemind> page = withdrawCashRemindService.findPage(new Page<WithdrawCashRemind>(request, response), withdrawCashRemind);
        model.addAttribute("page", page);
        return "modules/report/withdrawcashremind/withdrawCashRemindList";
    }

    @RequestMapping(value = "form")
    public String form(WithdrawCashRemind withdrawCashRemind, Model model) {
        model.addAttribute("withdrawCashRemind", withdrawCashRemind);
        return "modules/report/withdrawcashremind/withdrawCashRemindForm";
    }

    @RequestMapping(value = "save")
    public String save(WithdrawCashRemind withdrawCashRemind, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, withdrawCashRemind)) {
            return form(withdrawCashRemind, model);
        }
        withdrawCashRemindService.save(withdrawCashRemind);
        addMessage(redirectAttributes, "保存提现提醒成功");
        return "redirect:" + Global.getAdminPath() + "/withdrawcashremind/withdrawCashRemind/?repage";
    }

    @RequestMapping(value = "delete")
    public String delete(WithdrawCashRemind withdrawCashRemind, RedirectAttributes redirectAttributes) {
        withdrawCashRemindService.delete(withdrawCashRemind);
        addMessage(redirectAttributes, "删除提现提醒成功");
        return "redirect:" + Global.getAdminPath() + "/withdrawcashremind/withdrawCashRemind/?repage";
    }

}